package com.ruoyi.mymod.controller.feed;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.mymod.service.IFeedService;
import com.ruoyi.mymod.service.IMessageService;
import com.ruoyi.mymod.utils.Dbutil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;


/**
 * 测试功能
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/feed")
public class FeedController extends BaseController
{

    @Autowired
    private IFeedService feedService;
    /**
     * 获取菜单列表
     */
    @GetMapping("/getPrediction")
    public AjaxResult getPrediction(@RequestParam(required = false) String selectPigtype,@RequestParam(required = false) String nowweight, @RequestParam(required = false) String outweight, @RequestParam(required = false) String qty,@RequestParam(required = false) String distance) throws Exception {
        String prediction="";
        String date="1";
        if ("zz".equals(selectPigtype)){
            Dbutil.R r = feedService.getPrediction(selectPigtype,nowweight, outweight, qty,distance);
            prediction=r.json;

        }else if ("yf".equals(selectPigtype)){
            date = feedService.getDate(nowweight, outweight, qty);
            if (!"0".equals(date)){
                try {
                    Dbutil.R r = feedService.getPrediction(selectPigtype,nowweight, outweight, qty,distance);
                    prediction=r.json;
                } catch (Exception e) {
                    prediction=null;
                }
            }

        }

        if (!"0".equals(date) && prediction!=null){
            return success(date+"/"+prediction);
        }else {
            return error("请核对查询数据是否正确");
        }
    }


}
